package controller

import (
	"github.com/gin-gonic/contrib/sessions"
	"github.com/gin-gonic/gin"
	"mynetdisk/model"
	"net/http"
)

/**
 *@Author tudou
 *@Date 2019/8/24
 **/

//获取个人文件列表
func GetPersonalFile(c *gin.Context){
    session:=sessions.Default(c)
    user:=session.Get("user").(uint)
    var files model.Files
    if !files.GetPersonalFile(user){
    	c.JSON(http.StatusBadRequest,gin.H{"error":"get the information failed"})
    	return
	}
    c.JSON(http.StatusOK,files)
}

//获取公开文件列表
func GetPublicFile(c *gin.Context){
	var files model.Files
	if !files.GetPublicFile(){
		c.JSON(http.StatusBadRequest,gin.H{"error":"get the information failed"})
		return
	}
	c.JSON(http.StatusOK,files)
}

//获取用户可得到的文件列表
func GetUserFile(c *gin.Context){
	session:=sessions.Default(c)
	user:=session.Get("user").(uint)
	var files model.Files
	if !files.GetUserFile(user){
		c.JSON(http.StatusBadRequest,gin.H{"error":"get the information failed"})
		return
	}
	c.JSON(http.StatusOK,files)
}


